async function asyn1 () {
  console.log("async1 start");
  await asyn2();
  console.log('asyn1 end');
}

async function asyn2 () {
  console.log("async2 start");
}

setTimeout(function () {
  console.log("timerout");
}, 0);

console.log("script start");
asyn1();

new Promise(function (resolve, reject) {
  console.log("promise1");
  resolve();
}).then(res => {
  console.log("resolve");
});
console.log("script end");


// script start, async1 start, async2 start, promise1, script end, asyn1 end, resolve, timerout

/*
  解析：
  代码自上而下执行，同步代码依次执行，遇到定时器（宏任务）先放置到宏任务队列，遇到promise.then()会放置到微任务队列
  await async2()  ==> 会立即执行
  console.log('end')  ==> await下面的代码会包装成then，加入微任务队列
  ==>浏览器解析await： Promise.resolve(async2()).then(() => {console.log('end')})
  代码继续执行
  new Promise(function(resolve, reject) {
    console.log("promise");  // 立即执行
    resolve(); // 加入微任务队列
  }).then(() => {
    console.log("resolve");
  })

  宏任务：[timerout]
  微任务：[end， resolve]
  同步代码执行完之后，先清空微任务队列，按照先进先出执行
  然后再把宏任务里面取出一个来执行

 */